
package com.xd.common.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.text.SimpleDateFormat;
import java.util.Date;

@ApiModel(value = "cn.com.hatechframework.server.test.response.ResponseObject",description = "响应实体类")
public class ResponseObject<T> {
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @ApiModelProperty(name = "code", dataType = "Integer", value = "响应结果编码")
    private Integer code;
    @ApiModelProperty(name = "code", dataType = "String", value = "响应结果信息")
    private String msg;
    @ApiModelProperty(name = "code", dataType = "Long", value = "统计列表总数（如果列表存在）")
    private long count;
    @ApiModelProperty(name = "data", dataType = "Object", value = "响应结果数据")
    private T data;
    @ApiModelProperty(name = "time", dataType = "String", value = "响应结果时间")
    private String time;

    public ResponseObject() {
        this.time = this.sdf.format(new Date());
    }

    public ResponseObject(ResponseCode responseCode) {
        this.time = this.sdf.format(new Date());
        this.code = responseCode.code();
        this.msg = responseCode.message();
    }

    public ResponseObject(ResponseCode responseCode, long count, T data) {
        this.time = this.sdf.format(new Date());
        this.code = responseCode.code();
        this.msg = responseCode.message();
        this.count = count;
        this.data = data;
    }

    public ResponseObject<T> code(ResponseCode responseCode) {
        this.code = responseCode.code();
        this.msg = responseCode.message();
        return this;
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public long getCount() {
        return this.count;
    }

    public T getData() {
        return this.data;
    }

    public String getTime() {
        return this.time;
    }

    public ResponseObject<T> code(int code) {
        this.code = code;
        return this;
    }

    public ResponseObject<T> msg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResponseObject<T> count(long count) {
        this.count = count;
        return this;
    }

    public ResponseObject<T> data(T data) {
        this.data = data;
        return this;
    }

    public ResponseObject<T> time(String time) {
        this.time = time;
        return this;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setTime(String time) {
        this.time = time;
    }

    @Override
    public String toString() {
        return "ResponseObject{" +
                "sdf=" + sdf +
                ", code=" + code +
                ", msg='" + msg + '\'' +
                ", count=" + count +
                ", data=" + data +
                ", time='" + time + '\'' +
                '}';
    }
}
